/**
 * @description:
 * @file: common.ts
 * @author: Evan
 * @date: 2025.04.14 10:07:17
 * @week: 周一
 * @version: V
 * */

import { Api, Axios } from '@/api'
import { encryptAES } from '@/utils/encryption'
import type { UserInfo, NavItem } from './type'

// 登录
export const login = (
  params: Pick<AxiosParams, 'username' | 'password'>,
  loading: Parameters<typeof Axios.post>[2]
): Promise<Pick<AxiosRespon, 'access_token'>> => {
  return Axios.post(
    Api.common.mock.login,
    {
      ...params,
      password: encryptAES(params.password)
    },
    loading
  )
}

// 获取用户信息
export const getUserInfo = (): Promise<UserInfo> => {
  return Axios.get(Api.common.mock.get_userinfo)
}

// 获取用户权限
export const getUserAuth = (): Promise<NavItem[]> => {
  return Axios.get(Api.common.mock.user_auth)
}

// 获取权限项目列表
export const getUserAuthProjects = (): Promise<Pick<AxiosRespon, 'name' | 'id'>[]> => {
  return Axios.get(Api.common.mock.auth_project)
}

// 获取项目详情
export const getProjectDetail = (
  id: string
): Promise<Pick<AxiosRespon, 'logo' | 'logoSmall' | 'name'>> => {
  return Axios.get(Api.common.mock.get_project_detail, { id })
}

// 退出登录
export const logout = () => {
  return Axios.get(Api.common.mock.logout)
}

// 获取能耗分类-分项
export const getEnergySubCategory = (type: string): Promise<Pick<AxiosRespon, 'name' | 'id'>[]> => {
  return Axios.get(Api.common.mock.energy_sub_category, { type })
}

// 获取时间类型
export const getTimeType = (): Promise<Pick<AxiosRespon, 'name' | 'code'>[]> => {
  return Axios.get(Api.common.mock.time_type)
}

// 获取维度树
export const getDimensionTree = (nodeType: number) => {
  return Axios.get(Api.common.mock.dimension_tree, { nodeType })
}

// 获取图表随机数据
export const getEchartsRandomData = () => {
  return Axios.get(Api.common.mock.echarts_random)
}

// 获取图表数据
export const getEchartsData = (
  params: Pick<AxiosQuery, 'startTime' | 'endTime' | 'timeInterval'>
) => {
  return Axios.get(Api.common.mock.echarts_data, params)
}

// 获取图标数据-多时间节点
export const getEchartsDataByTimes = (
  params: Pick<AxiosQuery, 'timeStampList' | 'areaIds' | 'viewType' | 'queryType'>
) => {
  return Axios.get(Api.common.mock.echarts_times_data, params)
}

// 获取下拉列表
export const getSelectList = (name: string): Promise<Pick<AxiosRespon, 'id' | 'name'>[]> => {
  return Axios.get(Api.common.mock.select_list, { name })
}

// 获取下拉树
export const getSelectTree = (name: string): Promise<import('./type').SelectTree[]> => {
  return Axios.get(Api.common.mock.select_tree, { name })
}

// 获取表格分页数据
export const getTablePage = (
  params?: Partial<Record<'page' | 'pageSize', number>>
): Promise<import('./type').Table> => {
  return Axios.get(Api.common.mock.table_page, params)
}

// 获取表格数据详情
export const getTableDetails = (
  id: Pick<AxiosQuery, 'id'>['id'],
  min?: number,
  max?: number
): Promise<AnyObject> => {
  return Axios.get(Api.common.mock.table_get, { id, min, max })
}

// 测试接口
export const testApi = (params?: AnyObject) => {
  return Axios.get(Api.common.mock.test, params)
}

// 模型上传操心
export const uploadModel = () => {
  return Axios.get(Api.common.mock.model_upload, {}, false)
}
